﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JTicket.BLL;

namespace JTicket.UI
{
    public partial class JT_SystemReturn : RoleBase
    {
     private readonly  BLL.D_OperInfo bllOper = new BLL.D_OperInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }
        protected void dg1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemIndex == -1) return;
            e.Item.Attributes.Add("bgcolor", "#EFFFDA");
            e.Item.Attributes.Add("style", "cursor:hand");
            e.Item.Attributes.Add("onMouseOver=this.style.backgroundColor", "#DBE3FA");
            e.Item.Attributes.Add("onMouseOut=this.style.backgroundColor", "#F6F6F6");

        }
        void Bind()
        {
            int pages=1;
            BLL.C_TheaterInfo bllTheaterInfo = new BLL.C_TheaterInfo();
            List<Model.C_TheaterInfo> theater = bllTheaterInfo.GetListByCurLevel(0, 300, ref pages, ""); 
            this.DropDownList2.DataSource = theater;
            this.DropDownList2.DataTextField = "ThName";
            this.DropDownList2.DataValueField = "ThCode";
            this.DropDownList2.DataBind();
            
            this.txtBeginTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            this.txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;

            if (DropDownList2.Items.Count > 0)
            {
               
                List<Model.D_TitleInfo> tileList =
                BLL.D_TitleInfo.GestListAll(DropDownList2.SelectedItem.Value,
                   DateTime.Parse(btime), DateTime.Parse(etime));
                this.DropDownList1.DataSource = tileList;
                this.DropDownList1.DataTextField = "Stitlename";
                this.DropDownList1.DataValueField = "StitleCode";
                this.DropDownList1.DataBind();
            }
            string opercode = bllOper.Oper().OperCode;
            List<Model.L_ReturnProc> list = DAL.H_TicketBal.ReutnLog(opercode);
            this.dg2.DataSource = list;
            this.dg2.DataBind();
        }
        protected void txtBeginTime_TextChanged(object sender, EventArgs e)
        {
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
          
            List<Model.D_TitleInfo> tileList = BLL.D_TitleInfo.
                 GestListAll(bllOper.Oper().ThCode,
                 DateTime.Parse(btime), DateTime.Parse(etime));
            this.DropDownList1.DataSource = tileList;
            this.DropDownList1.DataTextField = "Stitlename";
            this.DropDownList1.DataValueField = "StitleCode";
            this.DropDownList1.DataBind();
        }
        protected void txtEndTime_TextChanged(object sender, EventArgs e)
        {
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            
            List<Model.D_TitleInfo> tileList = BLL.D_TitleInfo.
               GestListAll(bllOper.Oper().ThCode,
               DateTime.Parse(btime), DateTime.Parse(etime));
            this.DropDownList1.DataSource = tileList;
            this.DropDownList1.DataTextField = "Stitlename";
            this.DropDownList1.DataValueField = "StitleCode";
            this.DropDownList1.DataBind();
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (dg1.Items.Count > 0)
            {
                string BarCode = dg1.Items[0].Cells[0].Text;
                string TitleCode = dg1.Items[0].Cells[1].Text;
                string Area = dg1.Items[0].Cells[4].Text;
                string Row = dg1.Items[0].Cells[6].Text;
                string Cow = dg1.Items[0].Cells[7].Text;
                string Note = dg1.Items[0].Cells[5].Text;
                string sixid = dg1.Items[0].Cells[8].Text;
                string TicketName = dg1.Items[0].Cells[9].Text;
                string OperCode = bllOper.Oper().OperCode;
                string Model = "退票";
                bool b = false;
                b = DAL.H_TicketBal.ReturnTicket
                       (BarCode, TitleCode, Area, Row, Cow, Note, TicketName, OperCode, Model);
                if (b)
                {
                    Common.JsMsg.Alert("退票操作成功！");
                    Bind();
                }
                else
                    Common.JsMsg.Alert("退票操作失败，请重新操作！");
            }
            else
                Common.JsMsg.Alert("请先查询到要退的门票！");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count > 0)
            {
                List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachr(DropDownList1.SelectedItem.Value, this.t5.Text);
                this.dg1.DataSource = list;
                this.dg1.DataBind();
            }
            else
            {
                Common.JsMsg.Alert("请选择演出！");
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count > 0)
            {
                List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachrFlag(DropDownList1.SelectedItem.Value, this.t6.Text);
                this.dg1.DataSource = list;
                this.dg1.DataBind();
            }
            else
            {
                Common.JsMsg.Alert("请选择演出！");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count > 0)
            {
                List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachr(DropDownList1.SelectedItem.Value, this.t2.Text, this.t3.Text, this.t4.Text);
                this.dg1.DataSource = list;
                this.dg1.DataBind();
            }
            else
            {
                Common.JsMsg.Alert("请选择演出！");
            }
        }
    }
}